﻿//**********************************************************
//Copyright(C)2010 By 波特商网公司 版权所有。
//
//文件名：
//文件功能：图片按钮控件
//
//创建标识： || 2011-03-24
//
//修改标识：
//修改描述：
//**********************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using Hmc.IM.Common.Properties;

namespace Hmc.IM.Common.UserControls
{
    /// <summary>
    /// 图片按钮控件
    /// </summary>
    public class UCButton : PictureBox
    {
        private Label lb = new Label();

        private string _text;
        /// <summary>
        /// 显示的文本
        /// </summary>
        public string ShowText
        {
            get { return _text; }
            set { this._text = value; lb.Text = value; }
        }
        private BackgroundStyle buttomStyle = BackgroundStyle.one;

        /// <summary>
        /// 按钮样式
        /// </summary>
        public BackgroundStyle ButtomStyle
        {
            get { return buttomStyle; }
            set { buttomStyle = value; this.BackgroundImage = StyleList[value].CurrentImage; }
        }
        Dictionary<BackgroundStyle, BackgroundImageStyle> StyleList = new Dictionary<BackgroundStyle, BackgroundImageStyle>();
        /// <summary>
        /// 构造函数
        /// </summary>
        public UCButton()
        {
            this.BackColor = Color.Transparent;
            StyleList.Add(BackgroundStyle.one,new BackgroundImageStyle(Resources.in1, Resources.on1, Resources.in3));
            StyleList.Add(BackgroundStyle.two,new BackgroundImageStyle(Resources.in2, Resources.on2, Resources.on3));
            this.TabStop = true;
            lb.AutoSize = false;
            lb.BackColor = Color.Transparent;
            lb.ForeColor = Color.FromArgb(20, 110, 172);
            lb.Dock = DockStyle.Fill;
            lb.TextAlign = ContentAlignment.MiddleCenter;
            lb.Parent = this;
            lb.Click += new EventHandler(lb_Click);
            lb.MouseEnter += new EventHandler(lb_MouseEnter);
            lb.MouseLeave += new EventHandler(lb_MouseLeave);
            lb.MouseDown += new MouseEventHandler(lb_MouseDown);
            lb.MouseUp += new MouseEventHandler(lb_MouseUp);
            this.BackgroundImage = StyleList[this.buttomStyle].CurrentImage;
            this.Width = 67;
            this.Height = 22;
        }

        void lb_MouseUp(object sender, MouseEventArgs e)
        {
            OnMouseUp(e);
        }

        void lb_MouseDown(object sender, MouseEventArgs e)
        {
            OnMouseDown(e);
        }

        void lb_MouseLeave(object sender, EventArgs e)
        {
            OnMouseLeave(e);
        }

        void lb_MouseEnter(object sender, EventArgs e)
        {
            OnMouseEnter(e);
        }

        void lb_Click(object sender, EventArgs e)
        {
            OnClick(e);
        }

        /// <summary>
        /// 点击事件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
        }

        /// <summary>
        /// 鼠标进入当前区域
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseEnter(EventArgs e)
        {
            this.BackgroundImage = StyleList[this.buttomStyle].ActivityImage;
            base.OnMouseEnter(e);
        }

        /// <summary>
        /// 鼠标离开当前区域
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseLeave(EventArgs e)
        {
            this.BackgroundImage = StyleList[this.buttomStyle].CurrentImage;
            base.OnMouseLeave(e);
        }

        /// <summary>
        /// 鼠标点击
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            this.BackgroundImage = StyleList[this.buttomStyle].ClickImage;
            base.OnMouseDown(e);
        }

        /// <summary>
        /// 点击鼠标释放
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            this.BackgroundImage = StyleList[this.buttomStyle].CurrentImage;
            base.OnMouseUp(e);
        }

        /// <summary>
        /// 背景图片样式
        /// </summary>
        class BackgroundImageStyle
        {
            Image currentImage;

            /// <summary>
            /// 当前图片
            /// </summary>
            public Image CurrentImage
            {
                get { return currentImage; }
                set { currentImage = value; }
            }
            Image activityImage;
            /// <summary>
            /// 活动图片
            /// </summary>
            public Image ActivityImage
            {
                get { return activityImage; }
                set { activityImage = value; }
            }
            Image clickImage;
            /// <summary>
            /// 点击图片
            /// </summary>
            public Image ClickImage
            {
                get { return clickImage; }
                set { clickImage = value; }
            }
            public BackgroundImageStyle(Image current, Image activity, Image click)
            {
                this.currentImage = current;
                this.activityImage = activity;
                this.clickImage = click;
            }
        }

        /// <summary>
        /// 按钮背景样式
        /// </summary>
        public enum BackgroundStyle
        {
            /// <summary>
            /// 一种
            /// </summary>
            one,
            /// <summary>
            /// 二种
            /// </summary>
            two
        }
    }
}
